package com.monboo.album.view.component
{
	import com.monboo.album.common.AlbumConst;
	import com.monboo.utils.FullState;
	import com.monboo.utils.GetStage;
	import com.monboo.album.view.AlbumInfoMediator;
	
	import flash.display.Sprite;
	
	public class AbstractChangeUI extends Sprite
	{	
		protected var toWidth:Number;
		protected var toHeight:Number;
		protected var w:Number;
		protected var h:Number;
		protected var top:Number;
		protected var left:Number;
		
		private var xOff:Number;
		private var yOff:Number;
		private var imageInfo:AlbumInfoMediator;
		
		public function AbstractChangeUI(_imageInfo:AlbumInfoMediator)
		{
			imageInfo = _imageInfo;
		}
		
		public function changeSize(pic:Sprite,degrees:Number=0):void {	
			w = imageInfo.sourceWidth;
			h = imageInfo.sourceHeight;
			if(FullState.fullState){			
				toWidth = GetStage.theStage().stageWidth;
				toHeight= GetStage.theStage().stageHeight;
				
				setSize(pic,toWidth,toHeight,w,h);
				setPosition(pic,toWidth,toHeight);
			}else{
				toWidth = imageInfo.imageWidth;
				toHeight = imageInfo.imageHeight;
				
				setSize(pic,toWidth,toHeight,w,h);
				setPosition(pic,toWidth, toHeight);
			}
		}
		
		protected function setSize(pic:Sprite,bigPicWidth:Number,bigPicHeight:Number,w:Number,h:Number):void{
			pic.parent.scaleX = pic.parent.scaleY = 1;
			if(w/h > bigPicWidth/bigPicHeight){
				pic.parent.scaleX = pic.parent.scaleY = bigPicWidth/w;
			}else if(w/h < bigPicWidth/bigPicHeight){
				pic.parent.scaleX = pic.parent.scaleY = bigPicHeight/h;
			}else if(w/h == bigPicWidth/bigPicHeight){
				pic.parent.scaleX = pic.parent.scaleY = bigPicWidth/w;
			}	
		}	
		protected function setPosition(pic:Sprite,w:Number,h:Number,degrees:Number=0):void{
			if(FullState.fullState){
				top=0;
				left=0;
			}else{
				top=imageInfo.imageY;
				left=imageInfo.imageX;			
			}
			
			xOff = (pic.parent.width-imageInfo.sourceWidth*pic.parent.scaleX)/2;
			yOff = (pic.parent.height-imageInfo.sourceHeight*pic.parent.scaleX)/2;
			
			pic.parent.x = (w - pic.parent.width)/2 + left + xOff;
			pic.parent.y = (h - pic.parent.height)/2 + top + yOff;
		}
	}
}